set -e

source ./make_openssl_3.0.7.sh

for i in {1..10000}
do
    $openssl ecparam -name SM2 -genkey -noout -out sm2key.pem
    $openssl ec -in sm2key.pem -text -noout -out keypair.txt
    TrimOpensslText keypair.txt
    public_key=$(GetNthLine keypair.txt 5)
    echo $public_key # 04 x y
    if [[ $public_key =~ ^0400 ]]
    then
        echo "!!!!found!!!! iteration times: " $i
        break
    fi
done

$openssl ec -in sm2key.pem -pubout -out sm2pubkey.pem
$openssl ec -pubin -in sm2pubkey.pem -outform DER -out sm2pubkey.der
FileHexDump sm2pubkey.der
